/*    */ package com.zimbra.cs.service.admin;
/*    */ 
/*    */ import com.zimbra.common.account.Key.ServerBy;
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.AdminConstants;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.cs.account.AccessManager.AttrRightChecker;
/*    */ import com.zimbra.cs.account.AccountServiceException;
/*    */ import com.zimbra.cs.account.AttributeClass;
/*    */ import com.zimbra.cs.account.Provisioning;
/*    */ import com.zimbra.cs.account.Server;
/*    */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*    */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ import java.util.Set;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class GetServer
/*    */   extends AdminDocumentHandler
/*    */ {
/*    */   public Element handle(Element request, Map<String, Object> context)
/*    */     throws ServiceException
/*    */   {
/* 48 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/* 49 */     Provisioning prov = Provisioning.getInstance();
/*    */     
/* 51 */     boolean applyConfig = request.getAttributeBool("applyConfig", true);
/* 52 */     Set<String> reqAttrs = getReqAttrs(request, AttributeClass.server);
/*    */     
/* 54 */     Element d = request.getElement("server");
/* 55 */     String method = d.getAttribute("by");
/* 56 */     String name = d.getText();
/*    */     
/* 58 */     if ((name == null) || (name.equals(""))) {
/* 59 */       throw ServiceException.INVALID_REQUEST("must specify a value for a server", null);
/*    */     }
/* 61 */     Server server = prov.get(Key.ServerBy.fromString(method), name);
/*    */     
/* 63 */     if (server == null) {
/* 64 */       throw AccountServiceException.NO_SUCH_SERVER(name);
/*    */     }
/* 66 */     AdminAccessControl aac = checkRight(zsc, context, server, AdminRight.PR_ALWAYS_ALLOW);
/*    */     
/*    */ 
/* 69 */     prov.reload(server);
/*    */     
/* 71 */     Element response = zsc.createElement(AdminConstants.GET_SERVER_RESPONSE);
/* 72 */     encodeServer(response, server, applyConfig, reqAttrs, aac.getAttrRightChecker(server));
/*    */     
/* 74 */     return response;
/*    */   }
/*    */   
/*    */   public static void encodeServer(Element e, Server s) throws ServiceException {
/* 78 */     encodeServer(e, s, true, null, null);
/*    */   }
/*    */   
/*    */   public static void encodeServer(Element e, Server s, boolean applyConfig, Set<String> reqAttrs, AccessManager.AttrRightChecker attrRightChecker) throws ServiceException
/*    */   {
/* 83 */     Element server = e.addElement("server");
/* 84 */     server.addAttribute("name", s.getName());
/* 85 */     server.addAttribute("id", s.getId());
/* 86 */     Map<String, Object> attrs = s.getUnicodeAttrs(applyConfig);
/*    */     
/* 88 */     ToXML.encodeAttrs(server, attrs, reqAttrs, attrRightChecker);
/*    */   }
/*    */   
/*    */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*    */   {
/* 93 */     relatedRights.add(Rights.Admin.R_getServer);
/* 94 */     notes.add(String.format("Attributes that are not allowed to be get by the authenticated admin will be returned as <a n=\"{attr-name}\" pd=\"1\"/>.To allow an admin to get all attributes, grant the %s right", new Object[] { Rights.Admin.R_getServer.getName() }));
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/GetServer.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */